from pygame import font as pf

from config import win_size
from libs.fun import center_x , center
from libs.fun import center_y

pf.init ( )


class ZText ( object ) :
    def __init__ ( self , father , src_font , text , font_size , color ) :
        super ( ZText , self ).__init__ ( )
        self.father = father
        self.font = pf.Font ( src_font , font_size )
        self.text = text
        self.font_size = font_size
        self.color = color
        self.image = self.font.render ( self.text , True , self.color ).convert_alpha ( )
        self.rect = self.image.get_rect ( )

    def draw ( self , **kwargs ) :
        if kwargs.get ( "text" ) :
            if not self.text == kwargs.get ( "text" ) :
                self.text = kwargs.get ( "text" )
                self.image = self.font.render ( self.text , True , self.color ).convert_alpha ( )

        self.father.surface.blit ( self.image , self._pos )

    def update ( self , event , keys , m_keys , m_pos ) :
        pass

    def center_x ( self ) :
        self._pos = center_x ( self.father._size , self._size , self._pos )

    def center_y ( self ) :
        self._pos = center_y ( self.father._size , self._size , self._pos )

    def center ( self ) :
        self._pos = center ( self.father._size , self._size )

    @property
    def _size ( self ) :
        return self.rect.size

    @_size.getter
    def _size ( self ) :
        return self.rect.size

    @_size.setter
    def _size ( self , size ) :
        self.rect.size = size

    @property
    def _pos ( self ) :
        return self.rect.topleft

    @_pos.getter
    def _pos ( self ) :
        return self.rect.topleft

    @_pos.setter
    def _pos ( self , pos ) :
        self.rect.topleft = map ( lambda (a , b ) : a + b , zip ( self.father._pos , pos ) )
